package de.nordakademie.wpk.share.core.data.treeitem;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * Represents a node (incl. root and leave) of a tree used for the ui treeview
 * 
 * @author Christian Baumhof
 * 
 */
public class TreeItem implements Serializable {

	private static final long serialVersionUID = -6676796569917467159L;

	/**
	 * Identifies a TreeItem as share, index, depot or treeitem (e.g. root)
	 * 
	 * @author Christian Baumhof
	 * 
	 */
	public static enum Type {
		SHARE, INDEX, DEPOT, TREEITEM
	}

	private List<TreeItem> children = new ArrayList<TreeItem>();
	private TreeItem parent;
	private String title = "";

	public TreeItem() {
	}

	public TreeItem(String title) {
		this.title = title;
	}

	public void addChild(TreeItem child) {
		children.add(child);
		child.setParent(this);
		child.removeChildren();
	}

	public List<TreeItem> getChildren() {
		return children;
	}

	public void removeChildren() {
		children = new ArrayList<TreeItem>();
	}

	public TreeItem getParent() {
		return parent;
	}

	public void setParent(TreeItem parent) {
		this.parent = parent;
	}

	public TreeItem.Type getType() {
		return TreeItem.Type.TREEITEM;
	}

	public String getTitle() {
		return title;
	}

}
